﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using ZCrawler;

namespace ZCrawlerManager
{
    public class Procedure
    {
        public string TaskID { get; set; }
        public ZTask task { get; set; }
        public Task taskHandler;
        public Action<ZTask> onCompletionHandler;
        public void Start()
        {
            taskHandler = new Task(() =>
            {
                task.Launch();
            });
            taskHandler.Start();
            taskHandler.ContinueWith(onProcedureFinished);
        }

        private void onProcedureFinished(Task t)
        {
            if (onCompletionHandler != null) onCompletionHandler(task);
        }

        public void Stop()
        {
            task.Terminate();
        }

        public string IsRunning
        {
            get
            {
                return task.status.ToString();
            }
        }
    }
}
